import time
import logging
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

logger = logging.getLogger(__name__)


class BasePage:
    """简化版基础页面类"""

    def __init__(self, driver):
        self.driver = driver
        self.wait = WebDriverWait(driver, 10)

    def find_element(self, by, value, timeout=10):
        """查找元素"""
        return WebDriverWait(self.driver, timeout).until(
            EC.presence_of_element_located((by, value))
        )

    def click_element(self, by, value):
        """点击元素"""
        element = self.wait.until(EC.element_to_be_clickable((by, value)))
        element.click()

    def take_screenshot(self, name):
        """截图"""
        self.driver.save_screenshot(f"{name}.png")
        logger.info(f"截图保存: {name}.png")